import 'package:blue_plugin/bean/scan_result.dart';
import 'package:blue_plugin_example/dialog/dialog_base_nolist.dart';
import 'package:blue_plugin_example/res/colors.dart';
import 'package:blue_plugin_example/res/style.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:get/get.dart';

//蓝牙未打开的提示
class BlueSelectDialog extends StatelessWidget {
  ///右侧事件
  late Function(int index)? nextTap;
  late VoidCallback? backTap;
  late List<ScanResults> devList;

  BlueSelectDialog(List<ScanResults> this.devList,
      {Key? key, this.backTap, this.nextTap})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return BaseNoListDialog(
        height: (devList.length<=3)? 160:260,
        child: Column(
          mainAxisAlignment: MainAxisAlignment.start,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: <Widget>[
            Box.vBox16,
            const Text(
              "选择蓝牙",
              style: Styles.style_black_18_bold500,
            ),
            Box.vBox10,
            DividerStyle.divWid,
            Expanded(
              child: ListView.separated(
                itemBuilder: (BuildContext context, int index) {
                  return getItem(devList[index].localName!,index,nextTap);
                },
                itemCount: devList.length,
                separatorBuilder: (BuildContext context, int index) {
                  return DividerStyle.divWid;
                },
              ),
            ),
            Box.vBox20,
          ],
        ));
  }
}

Widget getItem(String? title, int? pos,Function(int index)? nextTap) {
  return GestureDetector(
    child: Container(
      height: 40,
      alignment: Alignment.center,
      child: Text(
        title!,
        style: const TextStyle(fontSize: 14, color: ColorStyle.text_color_1E1F20),
      ),
    ),
    onTap: ()=>{    //单击
      nextTap!(pos!),
    },
  );
}
